<?php

namespace app\admin\controller;


class File extends Common {


    /*
    *	构造函数
    */
    function __construct(){
        parent::__construct();
    }

    public function index(){
        $pageParam = ['query'=>[]];
        $where = [];

        $file_name = input('file_name');
        if($file_name != ''){
            $where['f.file_name'] = array('like','%'.$file_name.'%');
            $pageParam['query']['file_name'] = $file_name;
        }

        $type = input('type');
        if(input('type') != '0'){
            switch ($type) {
                case '1':
                    $where['pb.id'] = array('<>','null');
                    break;
                case '2':
                    $where['n.id'] = array('<>','null');
                    break;
                case '3':
                    $where['p.id'] = array('<>','null');
                    break;
            }

        }

        $file_list = db('file')->alias('f')
        ->where($where)
        ->field('f.*')
        ->paginate(10,false,$pageParam)
        ->each(function($item,$key){
            // $notice_result = db('notice')->where(array('id'=>$item['nid'],'file_id'=>$item['id']))->find();
            // $item['title'] = '';
            // if(!empty($notice_result)){
            //     $item['title'] = '通知公告';
            // }

            // $publicity_result = db('publicity')->where(array('id'=>$item['pbid'],'file_id'=>$item['id']))->find();
            // if(!empty($publicity_result)){
            //     $item['title'] = '公示公告';
            // }

            // $policy_result = db('policy')->where(array('id'=>$item['pid'],'file_id'=>$item['id']))->find();
            // if(!empty($policy_result)){
            //     $item['title'] = '政府文件';
            // }

            $item['url'] = __ROOT__.'/static/uploads/'.$item['file_path'];
            return $item;
        });

        $page = $file_list->render();

        $this->assign('file_list',$file_list);
        $this->assign('file_name',$file_name);
        $this->assign('type',$type);
        $this->assign('page',$page);
        return 	$this->fetch();
    }

}